package com.ruoyi.hr.controller.hr.salary.specialPersonRegister;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.salary.SpecialPersonSalaryRegisterService;
import com.ruoyi.hr.util.BaseResult;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 特殊人员薪资登记
 * @date 2020/2/7
 */
@Controller
@RequestMapping("/specialPersonSalaryRegister")
public class SpecialPersonSalaryRegisterController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    SpecialPersonSalaryRegisterService specialPersonSalaryRegisterService;

    private String prefix = "hr/salary/specialPersonSalaryRegister";

    @GetMapping()
    public String specialPersonSalaryRegister() {
        return prefix + "/specialPersonSalaryRegister";
    }

    /**
     * 获取特殊人员登记数据
     *
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String, Object>> list = specialPersonSalaryRegisterService.findData(authorityList,map,isAdmin);
        return getDataTable(list);
    }

    /**
     * 封存
     */
    @PostMapping("/sealUp")
    @ResponseBody
    public BaseResult sealUp(String pgid,String term) {
        return specialPersonSalaryRegisterService.sealUp(pgid,term);
    }
}
